﻿using CommandLine;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NK.Tools.Options
{
    [Verb("smartgit", HelpText = "清理 smartgit 30 天")]
    public class CleanSmartGitOptions : OptionHandlerBase
    {
        [Option('p', "path", Required = false, HelpText = "smart git 设置文件路径")]
        public string SettingFilePath { get; set; }

        public override void HandleOption()
        {
            if (string.IsNullOrEmpty(SettingFilePath))
            {
                var appDataPath = Environment.GetEnvironmentVariable("APPDATA");

                var smartGitRootPath = Path.Combine(appDataPath, "syntevo", "SmartGit");

                // search version
                var directories = Directory.GetDirectories(smartGitRootPath);

                if (directories.Count() != 1)
                {
                    Console.WriteLine("You install more than one smart, not support!");
                    return;
                }

                SettingFilePath = Path.Combine(directories[0], "settings.xml");
                Console.WriteLine($"Find setting file: {SettingFilePath}");
            }



            if (File.Exists(SettingFilePath))
            {
                File.Delete(SettingFilePath);
                Console.WriteLine("Clean successful");
            }
            else
            {
                Console.WriteLine($"Clean Failed, Smartgit setting file not find in this path: {SettingFilePath}");
            }
        }
    }
}
